package com.example.demo.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

/**第三种Filter
 * @author LF
 * @date 2021/4/16 - 15:44
 */
@Configuration
public class WebConfig3 {
    /**
     * 注册第三方过滤器
     * 功能与spring mvc中通过配置web.xml相同
     * 优点，即可以自由配置拦截的URL
     * 所以一般使用这种方案
     * @return
     */
    @Bean
    FilterRegistrationBean<MyFilter> myFilterFilterRegistrationBean() {
        FilterRegistrationBean<MyFilter> bean = new FilterRegistrationBean<>();
        bean.setFilter(new MyFilter());
        //优先级
        bean.setOrder(-1);
        //拦截规则
        bean.setUrlPatterns(Arrays.asList("/*"));
        return bean;
    }
}
